﻿using System.Windows.Media;

namespace Plugins.Windows
{
    public class ColorsUtils
    {
        /// <summary>
        /// Converts hex string to Color. If string is bad. Returns white color
        /// </summary>
        /// <param name="hexString">hex string</param>
        /// <returns>Color</returns>
        public static Color HexToColor(string hexString)        
        {
            Color color = (Color) ColorConverter.ConvertFromString(hexString);
            return color == null ? Colors.White : color;
        }

        /// <summary>
        /// Converts hex string to SolidColorBrush
        /// </summary>
        /// <param name="hexString">hex string</param>
        /// <returns>SolidColorBrush</returns>
        public static SolidColorBrush HexToSolidBrush(string hexString)
        {
            return new SolidColorBrush(HexToColor(hexString));
        }        
    }
}
